﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://www.codeplex.com/EmlenMud
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BrainTechLLC;

namespace UserInterface
{
	public partial class StateEditor : UserControl
	{
		public int _lastRow = -1;

		protected List<State> _stateList;
		protected List<State> StateList
		{
			get { return _stateList; }
			set
			{
				_stateList = value;
				if (DesignMode) return;
				UpdateBindings();
			}
		}

		public void SetStateList(List<State> states)
		{
			StateList = states;
		}

		public void UpdateBindings()
		{
			if (_stateList != null)
			{
				stateBindingSource.DataSource = _stateList;
			}
		}

		public StateEditor()
		{
			InitializeComponent();
		}


		private void stateDataGridView_SelectionChanged(object sender, EventArgs e)
		{
			if (stateDataGridView.SelectedCells != null && stateDataGridView.SelectedCells.Count > 0)
			{
				DataGridViewCell cell = stateDataGridView.SelectedCells[0];

				if (cell.RowIndex == _lastRow)
					return;

				_lastRow = cell.RowIndex;
				State s = stateDataGridView.Rows[cell.RowIndex].DataBoundItem as State;

                if (s != null)
                {
                    stateBindingSourceDetails.DataSource = s;

                    if (s.BaseStateAction != null)
                        commandToPerformEditor1.SetItem(s.BaseStateAction);
                    else
                        commandToPerformEditor1.SetItem(new CommandToPerform());

                    propertyCollectionEditor1.PropList = s.ThingProperties.Props.AllItems;
                }
			}
		}

		private void stateNameTextBox_TextChanged(object sender, EventArgs e)
		{

		}

		private void associatedIDControl1_Load(object sender, EventArgs e)
		{

		}
	}
}
